# -*- coding: latin-1 -*-
'''
Created on 02/06/2011

@author: nmedina
'''


from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage

class PlantillaPedidoRealizado():
    def __init__(self,detalle,confeccion,pie):
        self.__texthtml = ""
        self.__IniciarHtml()
        self.__DetallePedido(detalle)
        self.__Detalleconfeccion(confeccion)
        self.__PiePagina(pie)
        print self.__texthtml
    def __IniciarHtml(self):
        self.__texthtml = """<html>
<head>
  <meta
 content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>emailbase</title>
</head>
<body
 style="color: rgb(0, 0, 0); background-color: rgb(224, 236, 248);"
 alink="#000099" link="#000099" vlink="#990099">
<span style="font-weight: bold;"></span><br>
<table
 style="text-align: left; width: 731px; height: 102px;"
 border="0" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td
 style="width: 127px; height: 100px;"><img
 style="width: 133px; height: 100px;" alt="osplad-1"
 src="cid:image1"></td>
      <td
 style="width: 584px; height: 100px; text-align: center; background-color: rgb(224, 236, 248);"><span
 style="font-family: Arial Black;">NOTIFICACI&Oacute;N
AUTOMATICA STOCK HARDWARE SEDE CENTRAL</span></td>
    </tr>
  </tbody>
</table>
<br>
"""
    def __DetallePedido(self,detalle):
        self.__texthtml = self.__texthtml + """<big>Su pedido ha sido realizado
correctamente, continuaci&oacute;n se pasa a detallar el
del mismo: </big>&nbsp;<br>
<ul style="font-weight: bold;">
"""
        for key in detalle:
            self.__texthtml = self.__texthtml + "<li><small>" + str(key)+ ":" + str(detalle[key])+ """</small></li>
"""
        self.__texthtml = self.__texthtml + """</ul>
"""
#<li><small>Nro
#de pedido: 1</small></li>
#  <li><small>fecha:
#02/06/2011</small></li>
#  <li><small>Persona
#que tomo el pedido: &nbsp;Nestor&nbsp;</small></li>
#</ul>
#"""
    def __Detalleconfeccion(self,detalleconfeccion):
        self.__texthtml = self.__texthtml + """<big>Detalle del pedido:</big><br>
<ul style="font-weight: bold;">
  """
        for key in detalleconfeccion:
            self.__texthtml = self.__texthtml + """<li><small>""" + str(key)+ """(Cantidad """ + str(detalleconfeccion[key])+ """</small></li>
"""
        
        self.__texthtml = self.__texthtml + """</ul>
"""

#  <li><small>Memoria
#ram DDR 2 (Cantidad 3)</small></li>
#  <li><small>Disco
#Rigido SATA (Cantidad 3)</small></li>
#</ul>
#"""
    def __PiePagina(self ,piepag):
        self.__texthtml = self.__texthtml + """<small style="font-weight: bold;">
""" + str(piepag)
    def __CerrarMensaje(self):
        self.__texthtml = self.__texthtml + """&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; </small>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
</body>
</html>"""
    def __CrearEmail(self):
         # Creo mensaje raiz
         self.__msg = MIMEMultipart('related')
         self.__msg['Subject'] = 'test message'
         self.__msg['From'] = strFrom
         self.__msg['To'] = strTo
         self.__msg.preamble = 'Notificacion automatica'

         # Encapsulate the plain and HTML versions of the message body in an
         # 'alternative' part, so message agents can decide which they want to display.
         msgAlternative = MIMEMultipart('alternative')
         self.__msg.attach(msgAlternative)
         # We reference the image in the IMG SRC attribute by the ID we give it below
         msgText = MIMEText(self.__texthtml)
         msgAlternative.attach(msgText)
         fp = open('osplad.jpg', 'rb')
         msgImage = MIMEImage(fp.read())
         fp.close()
         msgImage.add_header('Content-ID', '<image1>')
         self.__msg.attach(msgImage)
#    def GetEmail(self):
        



# Define these once; use them twice!
#strFrom = 'from@example.com'
#strTo = 'to@example.com'
#
## Create the root message and fill in the from, to, and subject headers
#msgRoot = MIMEMultipart('related')
#msgRoot['Subject'] = 'test message'
#msgRoot['From'] = strFrom
#msgRoot['To'] = strTo
#msgRoot.preamble = 'This is a multi-part message in MIME format.'
#
## Encapsulate the plain and HTML versions of the message body in an
## 'alternative' part, so message agents can decide which they want to display.
#msgAlternative = MIMEMultipart('alternative')
#msgRoot.attach(msgAlternative)
#
#msgText = MIMEText('This is the alternative plain text message.')
#msgAlternative.attach(msgText)
#
## We reference the image in the IMG SRC attribute by the ID we give it below
#msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>Nifty!', 'html')
#msgAlternative.attach(msgText)
#
## This example assumes the image is in the current directory
#fp = open('test.jpg', 'rb')
#msgImage = MIMEImage(fp.read())
#fp.close()
#
## Define the image's ID as referenced above
#msgImage.add_header('Content-ID', '<image1>')
#msgRoot.attach(msgImage)
#
## Send the email (this example assumes SMTP authentication is required)
#import smtplib
#smtp = smtplib.SMTP()
#smtp.connect('smtp.example.com')
#smtp.login('exampleuser', 'examplepass')
#smtp.sendmail(strFrom, strTo, msgRoot.as_string())
#smtp.quit()


#detalle = {"Nro pedido" : 1,"Etc":2}
#confeccion = {"memoria" : 3,"cabble" : 5}
#pie = "Pie de pagina"
#
#PlantillaPedidoRealizado(detalle,confeccion,pie)
